package com.mgface.zookeeper.premitive;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

/**
 * 命名服务（通过一个名称来标识服务或者资源）重在生成一个唯一标识
 * 
 * @author yuxiang
 *
 */
public class 命名服务 {

	public static void main(String[] args) throws Exception {
		CuratorFramework client = CuratorFrameworkFactory.builder()
				.connectString("localhost:2181,localhost:2182,localhost:2183").sessionTimeoutMs(10_000)
				.namespace("job").connectionTimeoutMs(10_000).retryPolicy(new ExponentialBackoffRetry(1_000, 3))
				.build();
		client.start();
		System.out.println("启动完毕...");
		String newpath = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
				.forPath("/type-");
		String newpath2 = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
				.forPath("/type-");
		String newpath3 = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
				.forPath("/type-");
		System.out.println(newpath + "|" + newpath2 + "|" + newpath3);
	}

}
